﻿/*
 * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：研发部
 * 日 期：2017.04.17
 * 描 述：公司管理	
 */
var refreshGirdData; // 更新数据
var selectedRow;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({ keyword: keyword });
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                learun.layerForm({
                    id: 'Form',
                    title: '添加公司',
                    url: top.$.rootUrl + '/LR_OrganizationModule/Company/Form',
                    width: 700,
                    height: 300,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                var keyValue = $('#gridtable').jfGridValue('F_CompanyId');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'Form',
                        title: '编辑公司',
                        url: top.$.rootUrl + '/LR_OrganizationModule/Company/Form',
                        width: 700,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('F_CompanyId');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/LR_OrganizationModule/Company/DeleteForm', { keyValue: keyValue }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/LR_OrganizationModule/Company/GetList',
                headData: [
                    { label: "单位名称", name: "F_FullName", width: 400, align: "left" },
                    { label: "单位简称", name: "F_ShortName", width: 300, align: "left" },
                    //{ label: "单位编码", name: "F_EnCode", width: 150, align: "left" },
                    //{
                    //    label: "单位性质", name: "F_Nature", width: 120, align: "left",
                    //    formatterAsync: function (callback, value) {
                    //        learun.clientdata.getAsync('CompanyNature', {
                    //            key: value,
                    //            companyId: companyId,
                    //            callback: function (item) {
                    //                callback(item.name);
                    //            }
                    //        });
                    //    }
                    //},
                    //{ label: "负责人", name: "F_Manager", width: 100, align: "left" },
                    //{ label: "电话", name: "F_OuterPhone", width: 150, align: "left" },
                    //{
                    //    label: "成立时间", name: "F_FoundedTime", width: 150, align: "left",
                    //    formatter: function (cellvalue) {
                    //        return learun.formatDate(cellvalue, 'yyyy-MM-dd');
                    //    }
                    //},
                    { label: "备注", name: "F_Description", width: 300, align: "left" }
                ],
                isTree: false,
                isTreeClose: false,
                mainId: 'F_CompanyId',
                parentId: 'F_ParentId'
            });
            page.search();
        },
        search: function (param) {
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    // 保存数据后回调刷新
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    }

    page.init();
}


